<div id="dialog-confirm" title="Delete File" style="display:none;">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure?</p>
</div>

<div class="left">
    <div class="title-page">Update Post</div>
    <?php if ($error) { ?>
        <div class="alert alert-error">
    	<ul>
		<?php
		foreach ($error as $er) {
		    echo "<li>" . $er . "</li>";
		}
		?>
    	</ul>
        </div>
    <?php } ?>
    <div class="list-upload">
	<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
	<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

	<?php
	$form = $this->beginWidget('CActiveForm', array(
	    'id' => 'post-form',
	    'enableAjaxValidation' => FALSE,
	    'enableClientValidation' => true,
	    'clientOptions' => array(
		'validateOnSubmit' => true
	    ),
	    'htmlOptions' => array(
		'class' => 'form-horizontal',
		'enctype' => "multipart/form-data"
	    )
	));
	?>
	<div class="edit-post-body">
	    <p>
		<?php
		echo $form->label($model, 'title');
		echo $form->textField($model, 'title', array('class' => 'input-post'));
		echo $form->error($model, 'title');

		echo $form->label($model, 'content');
		echo $form->textArea($model, 'content', array('class' => 'input-post', 'style' => 'margin: 0px; width: 636px; height: 161px;'));
		echo $form->error($model, 'content');
		?>

		<br>
		<br>
	    <div id="wrapper-photo-edit">
		<label>Photo</label>
		<?php
		//show attachment	
		if (isset($attachment['photo'])) {
		    foreach ($attachment['photo'] as $photo) {
			echo '<div class="wrapper-photo-edit-inner">
				<a title="Delete this Image" class="btn-delete-img delete-file" href="javascript:void(0)" post-id="' . $model->post_id . '" file-name="' . $photo . '" file-type="photo">
				<i class="icon-remove"></i></a>
				<img src="' . ImageHelper::thumb(64, 64, 'photo' . DIRECTORY_SEPARATOR . $photo) . '" />
			    </div>';
		    }
		    echo '<div class="clear"></div>';
		    $inputPhoto = 5 - count($attachment['photo']);
		    if ($inputPhoto > 0) {
			if ($inputPhoto !== 5)
			    echo '<br>More photo<br>';
			for ($i = 0; $i < $inputPhoto; $i++) {
			    echo "<input type='file' name='photo[]' accept='image/*'/><br>";
			}
		    }
		}
		?>
	    </div>

	    <br>    	

	    <div id="wrapper-audio-edit">
		<label>Audio</label>	  
		<?php
		$audio = $model->getAudio();
		if ($audio) {
		    echo '<div id="div-audio">' . $audio . '</div>';
		    echo '<a id="remove-audio" href="javascript:void(0)" class="delete-file"   post-id="' . $model->post_id . '" file-name="' . $attachment['audio'] . '" file-type="audio"><i class="icon-remove"></i> Delete</a>';
		} else {
		    echo "<input type='file' name='audio' accept='audio/*'/><br>";
		}
		?>	    			    		


	    </div>    	
	    <br>
	    <div id="wrapper-video-edit">
		<label>Video</label>	  
		<?php
		$video = $model->getVideo();
		if ($video) {
		    echo '<div id="div-video">' . $video . '</div>';
		    echo '<a id="remove-video" href="javascript:void(0)" class="delete-file"   post-id="' . $model->post_id . '" file-name="' . $attachment['video']['upload'] . '" file-type="video"><i class="icon-remove"></i> Delete</a>';
		} else {
		    echo "<input type='file' name='video' accept='video/*'/><br>";
		}
		?>		
	    </div>
	    <br>    		 
	    <?php
	    echo $form->label($model, 'tags');
	    echo $form->textField($model, 'tags', array('class' => 'input-post'));
	    echo $form->error($model, 'tags');
//
//	    echo $form->label($model, 'is_private');
//	    echo $form->dropDownList($model, 'is_private', array('0' => 'Public', '1' => 'Private'), array('class' => 'input-post'));
//	    echo $form->error($model, 'is_private');
	    ?>
	    <input type='hidden' value="<?php echo $model->post_type ?>" name="Posts[post_type]"/>
	    </p>
	</div>
	<div class="modal-footer">

	    <input type="submit" class="btn btn-info" value="Save changes" name='posting'/>
	</div>
	<?php
	$this->endWidget();
	?>

	<?php
	/*
	  switch ($model->post_type) {
	  case Posts::TYPE_TEXT:
	  $this->renderPartial('_form-text', array('model' => $model, 'update' => 1, 'attachment' => $attachment));
	  break;
	  case Posts::TYPE_PHOTO:
	  $this->renderPartial('_form-photo', array('model' => $model, 'update' => 1, 'attachment' => $attachment));
	  break;
	  case Posts::TYPE_AUDIO:
	  $this->renderPartial('_form-audio', array('model' => $model, 'update' => 1, 'attachment' => $attachment));
	  break;
	  case Posts::TYPE_VIDEO:default :
	  $this->renderPartial('_form-video', array('model' => $model, 'update' => 1, 'attachment' => $attachment));
	  break;
	  }
	 * 
	 */
	?>
    </div>



</div>
<div class="right">
    <div class="box-right">
	<?php $this->widget('application.widgets.loginbox.LoginBox'); ?>

    </div><!--box-right-->
    <div class="box-right">
	<img src="<?php echo WWW_URL ?>images/branches-bank-finder-banner.jpg" />
    </div><!--box-right-->
    <div class="box-right">
	<img src="<?php echo WWW_URL ?>images/branches-bank-finder-banner.jpg" />
    </div><!--box-right-->

</div><!--right-->

<script>
    $(document).ready(function() {
	$("#dialog-confirm").dialog({
	    autoOpen: false,
	    show: {
		effect: "bounce",
		duration: 1000
	    },
	    hide: {
		effect: "explode",
		duration: 1000
	    }
	});

	$('.delete-file').click(function() {
	    var oBtnDelete = $(this);
	    var postId = $(this).attr('post-id');
	    var fileName = $(this).attr('file-name');
	    var fileType = $(this).attr('file-type');
	    $("#dialog-confirm").dialog({
		buttons: {
		    "Yes": function() {

			$.post('<?php echo SITE_NAME_URL ?>post/delete_file', {fileName: fileName, fileType: fileType, postId: postId}, function(response) {

			});
			switch (fileType.toString()) {
			    case 'photo':
				$(oBtnDelete).parent().remove();
				$('#wrapper-photo-edit').append('<input type="file" name="photo[]" accept="image/*"><br>');
				break;
			    case 'audio':
				$(oBtnDelete).parent().find('#div-audio').remove();
				$(oBtnDelete).remove();
				$('#wrapper-audio-edit').append('<input type="file" name="audio" accept="audio/*"><br>');
				break;
			    case 'video':
				$(oBtnDelete).parent().find('#div-video').remove();
				$(oBtnDelete).remove();
				$('#wrapper-video-edit').append('<input type="file" name="viddeo" accept="video/*"><br>');
				break;
			}

			$(this).dialog("close");

		    },
		    Cancel: function() {
			$(this).dialog("close");
		    }
		},
		modal: true

	    });
	    $("#dialog-confirm").dialog("open");
	});
    });
</script>